package com.woniuxy.mesboot.service.impl;

import cn.hutool.core.date.DateTime;
import com.woniuxy.mesboot.dto.MatStorageDTO;
import com.woniuxy.mesboot.entity.MatIn;
import com.woniuxy.mesboot.entity.MatStorage;
import com.woniuxy.mesboot.mapper.MatInMapper;
import com.woniuxy.mesboot.mapper.MatStorageMapper;
import com.woniuxy.mesboot.service.MatinService;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

import javax.annotation.Resource;
import java.util.List;

@Service
public  class MatinServiceImpl  implements MatinService {
    @Resource
    private MatInMapper matInMapper;
    @Resource
    private MatStorageMapper matStorageMapper;
    @Override
    public int insertOrder(MatStorageDTO record) {
        MatIn order = new MatIn();
        Long matId = record.getMatId();
        order.setMatId(matId);
        order.setMatInDate(new DateTime());
        order.setMatInNum(record.getMatNum());
        MatStorage matStorage = matStorageMapper.selectByPrimaryKey((long) matId);
        Integer warehouseId = matStorage.getWarehouseId();
        order.setWarehouseId(warehouseId);
        order.setWorkNo("wn10087");
        return matInMapper.insertSelective(order);
    }

    @Override
    public List<MatIn> selectAll() {
        return matInMapper.selectAll();
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return matInMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(MatIn record) {
      return matInMapper.insert(record);
    }

    @Override
    public int insertSelective(MatIn record) {
        return matInMapper.insertSelective(record);
    }

    @Override
    public MatIn selectByPrimaryKey(Long id) {
        return matInMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(MatIn record) {
    return matInMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(MatIn record) {
        return matInMapper.updateByPrimaryKey(record);
    }
}
